<?php

	/*
	* file: show.php
	*
	* contents:	shows a document entry.
	*
	* author: Lisa Pedrazzi, Zanco Federico
	*/



	//main


	include("init.php");
	
	/* Parameters for the pages */ 
	  
	//Header
	$pageTitle = "Visualizza un documento";
	$pageDescription = "Pagina di visualizzazione di un documento";
	
	//Content
	$title = "Visualizza un documento";
	$errorsText = "";
	
	$text = "";
	

	//check if a key was posted
	if ( isset($_GET['doc_num']) && isset($_GET['from']) && isset($_GET['to']) ) {

		//make a query to get the requested document
		$query = "SELECT * FROM documents as d WHERE ";
		$query = $query . "d.doc_num='" . $_GET['doc_num'] . "' AND d.to='" . $_GET['to'] . "' AND d.from='" . $_GET['from'] . "'";
		
		$res = query($query, $con);
		
		//if the document has been found show it
		if (mysql_affected_rows($con) == 1) {
			$text = showEntry($res);
		} else {
			//else notify the error
			$errorsText = "Il documento richiesto non esiste!";
		}
	}
	
	showHeader($pageTitle, $pageDescription);
	showMenu();
	showContents($title, $errorsText, $text);
	showFooter($lastRev);
	
	disconnect($con);
	
?>
